package com.atguigu.gulimall.search.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadTest003pool {
    public static ExecutorService executorService = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws Exception{
        System.out.println("main...........start........");
//        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println("当前线程：" + Thread.currentThread().getId());
//            int i = 10 % 3;
//            System.out.println("运行结果：" + i);
//        }, executorService);

//        方法执行后的处理
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 % 4;
            System.out.println("运行结果：" + i);
            return i;
        }, executorService).handle((result,exception)->{
            if(result!=null){
                return result*2;
            }
            if(exception !=null){
                return 0;
            }
            return 0 ;
        });
        System.out.println("main...........end........"+future.get());
    }
    public  void thread(String[] args) {
        System.out.println("main...........start........");
        Thread01 thread01 = new Thread01();
        thread01.start();
        System.out.println("main...........end........");
    }
    public static class Thread01 extends Thread{
        @Override
        public void run() {
            System.out.println("当前线程："+Thread.currentThread().getId());
            int i = 10%3 ;
            System.out.println("运行结果："+i);
        }
    }
}